
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
  
  <!-- Licensed under the Apache 2.0 License -->
  <link rel="stylesheet" type="text/css" href="../../../../_static/fonts/open-sans/stylesheet.css" />
  <!-- Licensed under the SIL Open Font License -->
  <link rel="stylesheet" type="text/css" href="../../../../_static/fonts/source-serif-pro/source-serif-pro.css" />
  <link rel="stylesheet" type="text/css" href="../../../../_static/css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" href="../../../../_static/css/bootstrap-theme.min.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
    <title>jmetal.lab.statistical_test.critical_distance &#8212; jMetalPy 1.5.1 documentation</title>
    <link rel="stylesheet" href="../../../../_static/guzzle.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../../../_static/custom.css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="author" title="About these documents" href="../../../../about.html" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
  
   

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">jMetalPy 1.5.1 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="container-wrapper">

      <div id="mobile-toggle">
        <a href="#"><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span></a>
      </div>
  <div id="left-column">
    <div class="sphinxsidebar"><a href="
    ../../../../index.html" class="text-logo">jMetalPy</a>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <h2>Table Of Contents</h2>
  </div>
  <div class="sidebar-toc">
    
    
      <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../tutorials.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../multiobjective.algorithms.html">Multi-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../singleobjective.algorithms.html">Single-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../problems.html">Problems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../about.html">About</a></li>
</ul>

    
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <div id="main-search">
      <form class="form-inline" action="../../../../search.html" method="GET" role="form">
        <div class="input-group">
          <input name="q" type="text" class="form-control" placeholder="Search...">
        </div>
        <input type="hidden" name="check_keywords" value="yes" />
        <input type="hidden" name="area" value="default" />
      </form>
    </div>
  </div>
</div>
      
    </div>
  </div>
        <div id="right-column">
          
          <div role="navigation" aria-label="breadcrumbs navigation">
            <ol class="breadcrumb">
              <li><a href="../../../../index.html">Docs</a></li>
              
                <li><a href="../../../index.html">Module code</a></li>
              
              <li>jmetal.lab.statistical_test.critical_distance</li>
            </ol>
          </div>
          
          <div class="document clearer body">
            
  <h1>Source code for jmetal.lab.statistical_test.critical_distance</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="k">import</span> <span class="n">pyplot</span> <span class="k">as</span> <span class="n">plt</span>
<span class="kn">from</span> <span class="nn">statsmodels.stats.libqsturng</span> <span class="k">import</span> <span class="n">qsturng</span>

<span class="kn">from</span> <span class="nn">jmetal.lab.statistical_test.functions</span> <span class="k">import</span> <span class="n">ranks</span>


<div class="viewcode-block" id="NemenyiCD"><a class="viewcode-back" href="../../../../api/jmetal.lab.statistical_test.html#jmetal.lab.statistical_test.critical_distance.NemenyiCD">[docs]</a><span class="k">def</span> <span class="nf">NemenyiCD</span><span class="p">(</span><span class="n">alpha</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">num_alg</span><span class="p">,</span> <span class="n">num_dataset</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Computes Nemenyi&#39;s critical difference:</span>
<span class="sd">    * CD = q_alpha * sqrt(num_alg*(num_alg + 1)/(6*num_prob))</span>
<span class="sd">    where q_alpha is the critical value, of the Studentized range statistic divided by sqrt(2).</span>
<span class="sd">    :param alpha: {0.1, 0.999}. Significance level.</span>
<span class="sd">    :param num_alg: number of tested algorithms.</span>
<span class="sd">    :param num_dataset: Number of problems/datasets where the algorithms have been tested.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="c1"># get critical value</span>
    <span class="n">q_alpha</span> <span class="o">=</span> <span class="n">qsturng</span><span class="p">(</span><span class="n">p</span><span class="o">=</span><span class="mi">1</span> <span class="o">-</span> <span class="n">alpha</span><span class="p">,</span> <span class="n">r</span><span class="o">=</span><span class="n">num_alg</span><span class="p">,</span> <span class="n">v</span><span class="o">=</span><span class="n">num_alg</span> <span class="o">*</span> <span class="p">(</span><span class="n">num_dataset</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>

    <span class="c1"># compute the critical difference</span>
    <span class="n">cd</span> <span class="o">=</span> <span class="n">q_alpha</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">num_alg</span> <span class="o">*</span> <span class="p">(</span><span class="n">num_alg</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="mf">6.0</span> <span class="o">*</span> <span class="n">num_dataset</span><span class="p">))</span>

    <span class="k">return</span> <span class="n">cd</span></div>


<div class="viewcode-block" id="CDplot"><a class="viewcode-back" href="../../../../api/jmetal.lab.statistical_test.html#jmetal.lab.statistical_test.critical_distance.CDplot">[docs]</a><span class="k">def</span> <span class="nf">CDplot</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">alpha</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.05</span><span class="p">,</span> <span class="n">higher_is_better</span><span class="p">:</span> <span class="nb">bool</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">alg_names</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">output_filename</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s1">&#39;cdplot.eps&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; CDgraph plots the critical difference graph show in Janez Demsar&#39;s 2006 work:</span>
<span class="sd">    * Statistical Comparisons of Classifiers over Multiple Data Sets.</span>
<span class="sd">    :param results: A 2-D array containing results from each algorithm. Each row of &#39;results&#39; represents an algorithm, and each column a dataset.</span>
<span class="sd">    :param alpha: {0.1, 0.999}. Significance level for the critical difference.</span>
<span class="sd">    :param alg_names: Names of the tested algorithms.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">_join_alg</span><span class="p">(</span><span class="n">avranks</span><span class="p">,</span> <span class="n">num_alg</span><span class="p">,</span> <span class="n">cd</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        join_alg returns the set of non significant methods</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># get all pairs</span>
        <span class="n">sets</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="n">num_alg</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_alg</span><span class="p">):</span>
            <span class="n">elements</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span>
                <span class="n">avranks</span> <span class="o">-</span> <span class="n">avranks</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="n">avranks</span> <span class="o">-</span> <span class="n">avranks</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">cd</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">elements</span><span class="o">.</span><span class="n">size</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">sets</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="p">[</span><span class="n">avranks</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">avranks</span><span class="p">[</span><span class="n">elements</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]]]</span>
        <span class="n">sets</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">sets</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">sets</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="c1"># group pairs</span>
        <span class="n">group</span> <span class="o">=</span> <span class="n">sets</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">sets</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="k">if</span> <span class="n">sets</span><span class="p">[</span><span class="n">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">sets</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">]:</span>
                <span class="n">group</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">group</span><span class="p">,</span> <span class="n">sets</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:]))</span>

        <span class="k">return</span> <span class="n">group</span>

    <span class="c1"># Initial Checking</span>
    <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">results</span><span class="p">)</span> <span class="o">==</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">:</span>
        <span class="n">alg_names</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">index</span>
        <span class="n">results</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">values</span>
    <span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">results</span><span class="p">)</span> <span class="o">==</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span> <span class="ow">and</span> <span class="n">alg_names</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">alg_names</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span>
            <span class="p">[</span><span class="s1">&#39;Alg</span><span class="si">%d</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">alg</span> <span class="k">for</span> <span class="n">alg</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">results</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])])</span>

    <span class="k">if</span> <span class="n">results</span><span class="o">.</span><span class="n">ndim</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
        <span class="n">num_alg</span><span class="p">,</span> <span class="n">num_dataset</span> <span class="o">=</span> <span class="n">results</span><span class="o">.</span><span class="n">shape</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
            <span class="s1">&#39;Initialization ERROR: In CDplot(...) results must be 2-D array&#39;</span><span class="p">)</span>

    <span class="c1"># Get the critical difference</span>
    <span class="n">cd</span> <span class="o">=</span> <span class="n">NemenyiCD</span><span class="p">(</span><span class="n">alpha</span><span class="p">,</span> <span class="n">num_alg</span><span class="p">,</span> <span class="n">num_dataset</span><span class="p">)</span>

    <span class="c1"># Compute ranks. (ranks[i][j] rank of the i-th algorithm on the j-th problem.)</span>

    <span class="n">rranks</span> <span class="o">=</span> <span class="n">ranks</span><span class="p">(</span><span class="n">results</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">descending</span><span class="o">=</span><span class="n">higher_is_better</span><span class="p">)</span>

    <span class="c1"># Compute for each algorithm the ranking averages.</span>
    <span class="n">avranks</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">rranks</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
    <span class="n">indices</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argsort</span><span class="p">(</span><span class="n">avranks</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>
    <span class="n">avranks</span> <span class="o">=</span> <span class="n">avranks</span><span class="p">[</span><span class="n">indices</span><span class="p">]</span>

    <span class="c1"># Split algorithms.</span>
    <span class="n">spoint</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">num_alg</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>
    <span class="n">leftalg</span> <span class="o">=</span> <span class="n">avranks</span><span class="p">[:</span><span class="n">spoint</span><span class="p">]</span>
    <span class="n">rightalg</span> <span class="o">=</span> <span class="n">avranks</span><span class="p">[</span><span class="n">spoint</span><span class="p">:]</span>
    <span class="n">rows</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">num_alg</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>

    <span class="c1"># Figure settings.</span>
    <span class="n">highest</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">avranks</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>  <span class="c1"># highest shown rank</span>
    <span class="n">lowest</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">avranks</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>  <span class="c1"># lowest shown rank</span>
    <span class="n">width</span> <span class="o">=</span> <span class="mi">6</span>  <span class="c1"># default figure width (in inches)</span>
    <span class="n">height</span> <span class="o">=</span> <span class="p">(</span><span class="mf">0.575</span> <span class="o">*</span> <span class="p">(</span><span class="n">rows</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>  <span class="c1"># figure height</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">                        FIGURE</span>
<span class="sd">      (1,0)</span>
<span class="sd">        +-----+---------------------------+-------+</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        +-----+---------------------------+-------+ stop</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        +-----+---------------------------+-------+ sbottom</span>
<span class="sd">        |     |                           |       |</span>
<span class="sd">        +-----+---------------------------+-------+</span>
<span class="sd">            sleft                       sright     (0,1)</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">stop</span><span class="p">,</span> <span class="n">sbottom</span><span class="p">,</span> <span class="n">sleft</span><span class="p">,</span> <span class="n">sright</span> <span class="o">=</span> <span class="mf">0.65</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.15</span><span class="p">,</span> <span class="mf">0.85</span>

    <span class="c1"># main horizontal axis length</span>
    <span class="n">lline</span> <span class="o">=</span> <span class="n">sright</span> <span class="o">-</span> <span class="n">sleft</span>

    <span class="c1"># Initialize figure</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">),</span> <span class="n">facecolor</span><span class="o">=</span><span class="s1">&#39;white&#39;</span><span class="p">)</span>
    <span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_axes</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">set_axis_off</span><span class="p">()</span>

    <span class="c1"># Main horizontal axis</span>
    <span class="n">ax</span><span class="o">.</span><span class="n">hlines</span><span class="p">(</span><span class="n">stop</span><span class="p">,</span> <span class="n">sleft</span><span class="p">,</span> <span class="n">sright</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">xi</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
        <span class="c1"># Plot mayor ticks</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">vlines</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="n">xi</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                  <span class="n">ymin</span><span class="o">=</span><span class="n">stop</span><span class="p">,</span> <span class="n">ymax</span><span class="o">=</span><span class="n">stop</span> <span class="o">+</span> <span class="mf">0.05</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>
        <span class="c1"># Mayor ticks labels</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="n">xi</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                <span class="n">y</span><span class="o">=</span><span class="n">stop</span> <span class="o">+</span> <span class="mf">0.06</span><span class="p">,</span>
                <span class="n">s</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">lowest</span> <span class="o">+</span> <span class="n">xi</span><span class="p">),</span> <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;bottom&#39;</span><span class="p">)</span>
        <span class="c1"># Minor ticks</span>
        <span class="k">if</span> <span class="n">xi</span> <span class="o">&lt;</span> <span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">:</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">vlines</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">xi</span> <span class="o">+</span> <span class="mf">0.5</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                      <span class="n">ymin</span><span class="o">=</span><span class="n">stop</span><span class="p">,</span> <span class="n">ymax</span><span class="o">=</span><span class="n">stop</span> <span class="o">+</span> <span class="mf">0.025</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>

    <span class="c1"># Plot lines/names for left models</span>
    <span class="n">vspace</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">stop</span> <span class="o">-</span> <span class="n">sbottom</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">spoint</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">spoint</span><span class="p">):</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">vlines</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">leftalg</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                  <span class="n">ymin</span><span class="o">=</span><span class="n">sbottom</span> <span class="o">+</span> <span class="p">(</span><span class="n">spoint</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">i</span><span class="p">)</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span> <span class="n">ymax</span><span class="o">=</span><span class="n">stop</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">hlines</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">sbottom</span> <span class="o">+</span> <span class="p">(</span><span class="n">spoint</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">i</span><span class="p">)</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span> <span class="n">xmin</span><span class="o">=</span><span class="n">sleft</span><span class="p">,</span>
                  <span class="n">xmax</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span>
                       <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">leftalg</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                  <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">-</span> <span class="mf">0.01</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">sbottom</span> <span class="o">+</span> <span class="p">(</span><span class="n">spoint</span> <span class="o">-</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">i</span><span class="p">)</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span>
                <span class="n">s</span><span class="o">=</span><span class="n">alg_names</span><span class="p">[</span><span class="n">indices</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;right&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">)</span>

    <span class="c1"># Plot lines/names for right models</span>
    <span class="n">vspace</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">stop</span> <span class="o">-</span> <span class="n">sbottom</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">num_alg</span> <span class="o">-</span> <span class="n">spoint</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">num_alg</span> <span class="o">-</span> <span class="n">spoint</span><span class="p">):</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">vlines</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">rightalg</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                  <span class="n">ymin</span><span class="o">=</span><span class="n">sbottom</span> <span class="o">+</span> <span class="n">i</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span> <span class="n">ymax</span><span class="o">=</span><span class="n">stop</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">hlines</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">sbottom</span> <span class="o">+</span> <span class="n">i</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span>
                  <span class="n">xmin</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span>
                       <span class="p">(</span><span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">rightalg</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                  <span class="n">xmax</span><span class="o">=</span><span class="n">sright</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;black&#39;</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">0.7</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sright</span> <span class="o">+</span> <span class="mf">0.01</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">sbottom</span> <span class="o">+</span> <span class="n">i</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span>
                <span class="n">s</span><span class="o">=</span><span class="n">alg_names</span><span class="p">[</span><span class="n">indices</span><span class="p">][</span><span class="n">spoint</span> <span class="o">+</span> <span class="n">i</span><span class="p">],</span> <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">)</span>

    <span class="c1"># Plot critical difference rule</span>
    <span class="k">if</span> <span class="n">sleft</span> <span class="o">+</span> <span class="p">(</span><span class="n">cd</span> <span class="o">*</span> <span class="n">lline</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">sright</span><span class="p">:</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">hlines</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">stop</span> <span class="o">+</span> <span class="mf">0.2</span><span class="p">,</span> <span class="n">xmin</span><span class="o">=</span><span class="n">sleft</span><span class="p">,</span> <span class="n">xmax</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span>
                                                 <span class="p">(</span><span class="n">cd</span> <span class="o">*</span> <span class="n">lline</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">1.5</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">cd</span> <span class="o">*</span> <span class="n">lline</span><span class="p">)</span> <span class="o">/</span>
                  <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span> <span class="n">y</span><span class="o">=</span><span class="n">stop</span> <span class="o">+</span> <span class="mf">0.21</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="s1">&#39;CD=</span><span class="si">%.3f</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">cd</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;bottom&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="p">(</span><span class="n">sleft</span> <span class="o">+</span> <span class="n">sright</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">stop</span> <span class="o">+</span> <span class="mf">0.2</span><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="s1">&#39;CD=</span><span class="si">%.3f</span><span class="s1">&#39;</span> <span class="o">%</span>
                                                        <span class="n">cd</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s1">&#39;center&#39;</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">&#39;bottom&#39;</span><span class="p">)</span>

    <span class="c1"># Get pair of non-significant methods</span>
    <span class="n">nonsig</span> <span class="o">=</span> <span class="n">_join_alg</span><span class="p">(</span><span class="n">avranks</span><span class="p">,</span> <span class="n">num_alg</span><span class="p">,</span> <span class="n">cd</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">nonsig</span><span class="o">.</span><span class="n">ndim</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">nonsig</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">left_lines</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">nonsig</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:],</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
            <span class="n">right_lines</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">nonsig</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="p">:],</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">left_lines</span> <span class="o">=</span> <span class="n">nonsig</span><span class="p">[:</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span>
                <span class="n">nonsig</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">),</span> <span class="p">:]</span>
            <span class="n">right_lines</span> <span class="o">=</span> <span class="n">nonsig</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span>
                <span class="n">nonsig</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">):,</span> <span class="p">:]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">left_lines</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">nonsig</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">nonsig</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>

    <span class="c1"># plot from the left</span>
    <span class="n">vspace</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">stop</span> <span class="o">-</span> <span class="n">sbottom</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">left_lines</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">left_lines</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">hlines</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">stop</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span>
                  <span class="n">xmin</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">left_lines</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">-</span>
                                        <span class="n">lowest</span> <span class="o">-</span> <span class="mf">0.025</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                  <span class="n">xmax</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">left_lines</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">lowest</span> <span class="o">+</span> <span class="mf">0.025</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

    <span class="c1"># plot from the rigth</span>
    <span class="k">if</span> <span class="n">nonsig</span><span class="o">.</span><span class="n">ndim</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
        <span class="n">vspace</span> <span class="o">=</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="p">(</span><span class="n">stop</span> <span class="o">-</span> <span class="n">sbottom</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">left_lines</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">right_lines</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">hlines</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">stop</span> <span class="o">-</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">vspace</span><span class="p">,</span>
                      <span class="n">xmin</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">right_lines</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">-</span>
                                            <span class="n">lowest</span> <span class="o">-</span> <span class="mf">0.025</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span>
                      <span class="n">xmax</span><span class="o">=</span><span class="n">sleft</span> <span class="o">+</span> <span class="n">lline</span> <span class="o">*</span> <span class="p">(</span><span class="n">right_lines</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">lowest</span> <span class="o">+</span> <span class="mf">0.025</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">highest</span> <span class="o">-</span> <span class="n">lowest</span><span class="p">),</span> <span class="n">linewidth</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>

    <span class="n">plt</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">output_filename</span><span class="p">,</span> <span class="n">bbox_inches</span><span class="o">=</span><span class="s1">&#39;tight&#39;</span><span class="p">)</span>
    <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span></div>
</pre></div>

          </div>
            
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">jMetalPy 1.5.1 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
<script type="text/javascript">
  $("#mobile-toggle a").click(function () {
    $("#left-column").toggle();
  });
</script>
<script type="text/javascript" src="../../../../_static/js/bootstrap.js"></script>
  <div class="footer">
    &copy; Copyright 2019, Antonio Benítez-Hidalgo. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  </body>
</html>